#!/usr/bin/env python
# -*- coding: utf-8 -*-

import unittest
from drawer import*
from grid import SampleSettings


class TestDrawer(unittest.TestCase):

    def test_drawer_calc_dimensions(self):
        sampleSettings = SampleSettings(ySampleMin = -10, ySampleMax = 50, xSampleWidth = 50)
        drawer = Drawer(sampleSettings)
        drawer.calc_dimensions(sampleSettings, (0, 0))
        #print drawer.kxStoP, drawer.kyStoP, drawer.yPix0
        self.assertAlmostEqual(drawer.kxStoP, -1.6, 5)
        self.assertAlmostEqual(drawer.kyStoP, -1.333333, 5)
        self.assertAlmostEqual(drawer.yPix0, -26.66666, 3)

    def test_drawer_calc_dimensions2(self):
        sampleSettings = SampleSettings(-10, 50, 50)
        drawer = Drawer(sampleSettings)
        drawer.calc_dimensions(sampleSettings, (10, 0))
        #print drawer.kxStoP, drawer.kyStoP, drawer.yPix0
        self.assertAlmostEqual(drawer.kxStoP, -1.6, 5)
        self.assertAlmostEqual(drawer.kyStoP, -3.833333, 5)
        self.assertAlmostEqual(drawer.yPix0, -151.66666, 3)
        pass

    def test_drawer_calc_dimensions3(self):
        sampleSettings = SampleSettings(-555, 11677, 33453)
        drawer = Drawer(sampleSettings)
        drawer.calc_dimensions(sampleSettings, (5, 0))
        #print drawer.kxStoP, drawer.kyStoP, drawer.yPix0
        self.assertAlmostEqual(drawer.kxStoP, -0.0023914, 5)
        self.assertAlmostEqual(drawer.kyStoP, -0.0126716, 5)
        self.assertAlmostEqual(drawer.yPix0, -107.967217, 3)
        pass

if __name__ == "__main__":

    load_case = unittest.defaultTestLoader.loadTestsFromTestCase
    suite = load_case(TestDrawer)
    #suite.addTest(load_case(Test...))
    unittest.TextTestRunner(verbosity = 2).run(suite)

    #raw_input("press any key")
